function traj = rollout(weights, start_state, target_state, len_traj, n_traj, use_linear)

    init_setup;

    for i = 1:n_traj
        x(:,1) = start_state;
        for t=1:len_traj
            x_t = x(:, t);
            
            % control law:
            dx = compute_dx(target_state, x_t);

            % state observation noise:
            %v = randn(size(dx,1)-1,1)*.1;
            %dx(1:end-1) = dx(1:end-1) + v;

            delta_u = policy(x_t, dx, weights, use_linear);

            % simulate:
            %noise_F_T = randn(6,1)*1;
            x(:,t+1) = f_heli(x(:,t), delta_u, dt, model, idx);

            
            % If the helicopter crashed, just stop the rollout
            if(norm(x(idx.ned, t+1), 2) > 200)
                break;
            end
        end
        
        % If we stopped the rollout early, fill in the rest as the last
        % known position.
        if (t < len_traj)
            x(:, t+2:len_traj+1) = repmat(x(:, t+1), 1, len_traj - t);
        end
        
        traj(:, :, i) = x;
    end
  
end